﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GONES.IBLL;
using GONES.Tools.Common;
using GONES.Model;

public partial class Console_System_Navs_NavPermisionAdd : CPage
{
    public string NavId { get; set; }
    public string Title { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        NavId = Request.QueryString["PID"].ToString();
          var navManager = AppContext.GetObject("S_NavManager") as IS_NavManager;
        GONES.Model.S_Nav nav = new GONES.Model.S_Nav();
        nav = navManager.Get(NavId);
        if (nav != null)
        {
            Title = nav.Title.Trim();
        }
    }

    public string GetCheckBox()
    {
        string chkHtml = "";
        var permissionsManager = AppContext.GetObject("S_PermissionsManager") as IS_PermissionsManager;
        var navPermissionManager = AppContext.GetObject("S_NavPermissionManager") as GONES.IBLL.IS_NavPermissionManager;
        IList<DataFilter> dataFilters = new List<DataFilter>();
        long recordcount=0;
        IList<S_Permissions> permissionsList = permissionsManager.List(dataFilters, 1, 10, ref recordcount);
        IList<S_NavPermission> navpermissionsList = navPermissionManager.GetNavPermissionList(NavId);
        string pidstr = "";
        foreach (var navPer in navpermissionsList)
        {
            pidstr += navPer.PermisionId;
        }
        for (int i = 0; i < permissionsList.Count; i++)
        {
            if (!pidstr.Contains(permissionsList[i].ID))
            {
                chkHtml += string.Format(" <input type=\"checkbox\" size=30 name=box  value=\"{0}\">{1}</input>",
                    permissionsList[i].ID, permissionsList[i].Pname);
            }
            else
            {
                chkHtml += string.Format(" <input type=\"checkbox\" checked=\"checked\" size=30 name=box  value=\"{0}\">{1}</input>",
                                  permissionsList[i].ID, permissionsList[i].Pname);
            }
        }
        return chkHtml;
    }
}